package org.nanhill.xsheet.output.xhtml;

import static org.nanhill.commons.html.XhtmlConstants.*;

import org.nanhill.commons.model.table.Cell;
import org.nanhill.commons.model.table.Row;
import org.nanhill.commons.model.table.Table;
import org.nanhill.xsheet.output.AbstractOutputBuilder;

public abstract class XhtmlOutputBuilder extends AbstractOutputBuilder {
	protected StringBuilder htmlBuilder;

	public String getHtml() {
		return this.htmlBuilder.toString();
	}

	protected void buildHtmlBuilder() {
		this.htmlBuilder = new StringBuilder();
	}

	protected abstract void buildTables();

	protected abstract void buildTable(Table table);

	protected abstract void buildTr(Row row);

	protected abstract void buildTd(Cell cell);

	protected void buildHtmlStart() {
		this.htmlBuilder.append(HTML_START);
		this.buildHead();
		this.htmlBuilder.append(BODY_START);
	}

	protected void buildHtmlEnd() {
		this.htmlBuilder.append(BODY_END);
		this.htmlBuilder.append(HTML_END);
	}

	private void buildHead() {
		this.htmlBuilder.append(HEAD_START);
		this.htmlBuilder.append(META_CONTENT);
		this.htmlBuilder.append(TITLE_START);
		this.htmlBuilder.append(TITLE_END);
		this.htmlBuilder.append(HEAD_END);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.nanhill.xsheet.output.OutputBuilder#getProduct()
	 */
	public String getProduct() {
		return this.htmlBuilder.toString();
	}

}
